if(!dojo._hasResource["opm.widgets.GenericArrow"]){
dojo._hasResource["opm.widgets.GenericArrow"] = true;
dojo.provide("opm.widgets.GenericArrow");
dojo.require("dijit._Widget");;
dojo.declare("opm.widgets.GenericArrow",dijit._Widget,
{
   contentId:"",
   leftArrowData:"",
   rightArrowData:"",
   leftTitle:"",
   rightTitle:"",
   controlName:"",
   hasAllData:true,
   constructor:function(args){
      this.setAtts(args);
   },
   setAtts:function(args){
      this.contentId = args.contentId;
      this.leftArrowData = args.leftData.data;
      this.rightArrowData = args.rightData.data;
      this.leftTitle = args.leftData.title;
      this.rightTitle = args.rightData.title;
      this.controlName = args.controlName;
      this.hasAllData = args.hasAllData == null ? true : args.hasAllData;
   },
   generic:function(){
      dojo.byId(this.contentId).innerHTML = this._layout();
      this._initArrow();
   },
   _initArrow:function(){
      var arrowObject = this;
      dojo.query('#'+this.contentId+' [id="rightarrow"]').onclick(function(){
         var _arrowObject = arrowObject;
         var elements = dojo.query('#'+_arrowObject.contentId+' [name="selectedLeftData"]:checked');
         _arrowObject.movieLeftToRight(elements);
         _arrowObject.generic();
         _arrowObject._setData();
      });
      dojo.query('#'+this.contentId+' [id="leftarrow"]').onclick(function(){
         var _arrowObject = arrowObject;
         var elements = dojo.query('#'+_arrowObject.contentId+' [name="selectedRightData"]:checked');
         _arrowObject.movieRightToLeft(elements);
         _arrowObject.generic();
         _arrowObject._setData();
      });
   },
   getData : function (){
      var elements = dojo.query('#'+_arrowObject.contentId+' [name="selectedRightData"]');
      var rightDataSource = new Array();
      var elementLength = elements.size();
      for (var index=0; index<elementLength; index++){
         var element = elements.get(index);
         var elementId = element.value;
         if ((this.hasAllData == false && element.assigned != 'true') || this.hasAllData == true){
            rightDataSource.push(elementId);
         }
      }
      return rightDataSource;
   },
   setLeftData:function(leftData){
      this.leftArrowData = leftData;
      this.generic();
   },
   _setData : function (){
      var jsonText = "[";
      for (var index=0; index<this.rightArrowData.length; index++){
         var objectData = this.rightArrowData[index];
         if ((this.hasAllData == false && objectData.assigned != 'true') || this.hasAllData == true){
            jsonText += objectData.id + ",";
         }
      }
      if (jsonText.length > 1){
         jsonText = jsonText.substring(0, jsonText.length - 1);
      }
      jsonText += "]";
      dojo.query('#'+this.contentId+' [id="'+this.controlName+'"]')[0].value = jsonText;
   },
   movieLeftToRight:function(elements){
      var elementLength = elements.length;
      for (var nodeIndex=0; nodeIndex<elementLength; nodeIndex++){
         var element = elements[nodeIndex];
         var elementId = element.value;
         var index=0;
         for (; index<this.leftArrowData.length; index++){
            var objectData = this.leftArrowData[index];
            if (objectData.id==elementId){
               this.rightArrowData.push(objectData);
               break;
            }
         }
         this.leftArrowData.splice(index, 1);
      }
   },
   movieRightToLeft:function(elements){
      var elementLength = elements.length;
      for (var nodeIndex=0; nodeIndex<elementLength; nodeIndex++){
         var element = elements[nodeIndex];
         var elementId = element.value;
         var index=0;
         for (; index<this.rightArrowData.length; index++){
            var objectData = this.rightArrowData[index];
            if (objectData.id==elementId){
               this.leftArrowData.push(objectData);
               break;
            }
         }
         this.rightArrowData.splice(index, 1);
      }
   },
   _leftArrow:function(){
      var html = "<div>";
      html += '<table cellspacing="0" cellpadding="0" id="leftData" style="width: 100%;" class="table">';
      html += '<thead>';
      html += '<tr>';
      html += '<th class="sorted order1"><input name="mainSelectedLeftData" type="checkbox" /></th>';
      html += '<th>'+this.leftTitle+'</th>';
      html += '</tr>';
      html += '</thead>';
      for (var index=0; index<this.leftArrowData.length; index++){
         var objectData = this.leftArrowData[index];
         var styleRow = "class='odd'";
         if ((index % 2) == 0)
            styleRow = "class='even'";
         html += '<tr '+styleRow+'>';
         html += '<td style="width: 20px;">';
         html += '<input name="selectedLeftData" value="'+objectData.id+'" type="checkbox" /></td>';
         html += '<td>'+objectData.displayName+'</td>';  
         html += '</tr>';
      }     
      html += '</table>';
      html += '</div>';
      return html;
   },
   _rightArrow : function(){
      var html = '<div>';
      html += '<table cellspacing="0" cellpadding="0" id="rightData" style="width: 100%;" class="table">';
      html += '<thead>';
      html += '<tr>';
      html += '<th class="sorted order1"><input name="mainSelectedRightData" type="checkbox" /></th>';
      html += '<th>'+this.rightTitle+'</th>';  
      html += '</tr>';
      html += '</thead>';
      for (var index=0; index<this.rightArrowData.length; index++){
         var objectData = this.rightArrowData[index];
         var styleRow = "class='odd'";
         if ((index % 2) == 0)
            styleRow = "class='even'";
         html += '<tr '+styleRow+'>';
         html += '<td style="width: 20px;">';
         html += '<input name="selectedRightData" value="'+objectData.id+'" type="checkbox" ' + ((objectData.disabled == 'true')?'disabled="disabled"':'') +' /></td>';
         html += '<td>'+objectData.displayName+'</td>';  
         html += '</tr>';
      }     
      html += '</table>';
      html += '</div>';
      return html;
   },
   _menuArrow : function (){
      var html = "<div>";
      html += "<div class=\"arrow\"><div id=\"rightarrow\" class=\"rightarrow\"></div></div>";
      html += "<div class=\"arrow\"><div id=\"leftarrow\" class=\"leftarrow\"></div></div>";
      html += "<div class=\"arrow\"><div id=\"doublerightarrow\" class=\"doubleRightarrow\"></div></div>";
      html += "<div class=\"arrow\"><div id=\"doubleleftarrow\" class=\"doubleLeftarrow\"></div></div>";
      html += "</div>";
      return html;
   },
   _layout : function(){
      var html = '<div>';
      html += '<input type="hidden" id="'+this.controlName+'"/>';
      html += '<table id="tableArrow" cellspacing="0" cellpadding="0">';
      html += '<tr>';
      html += '<td id="navLeft">';
      html += this._leftArrow();
      html += '</td>';
      html += '<td id="navCenter">';
      html += this._menuArrow();
      html += '</td>';
      html += '<td id="navRight">';
      html += this._rightArrow();
      html += '</td>';
      html += '</tr>';
      html += '</table>';
      html += '</div>';
      return html;
   }
}
);
}